#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
//    setCentralWidget(ui->drawWidget);
    init();
}
void MainWindow::init(){
    ui->styleCombox->addItem("SolidLine", static_cast<int>(Qt::SolidLine));
    ui->styleCombox->addItem("DashLine", static_cast<int>(Qt::DashLine));
    ui->styleCombox->addItem("DotLine", static_cast<int>(Qt::DotLine));
    ui->styleCombox->addItem("DashDotLine", static_cast<int>(Qt::DashDotLine));
    ui->styleCombox->addItem("DashDotDotLine", static_cast<int>(Qt::DashDotDotLine));

    connect(ui->styleCombox, SIGNAL(activated(int)), this, SLOT(ShowStyle()));
    connect(ui->widthSpinBox, SIGNAL(valueChanged(int)), ui->drawWidget, SLOT(setWidth(int)));

    QPixmap pixmap(20, 20);
    pixmap.fill(Qt::black);
    ui->colorBtn->setIcon(QIcon(pixmap));

    connect(ui->colorBtn, SIGNAL(clicked()), this, SLOT(ShowColor()));
    connect(ui->clearBtn, SIGNAL(clicked()), ui->drawWidget, SLOT(clear()));

}

void MainWindow::ShowStyle(){
    ui->drawWidget->setStyle(ui->styleCombox->itemData(ui->styleCombox->currentIndex()).toInt());
}
void MainWindow::ShowColor(){
    QColor color = QColorDialog::getColor(static_cast<int>(Qt::black), this);
    if(color.isValid()){
        ui->drawWidget->setColor(color);
        QPixmap pix(20, 20);
        pix.fill(color);
        ui->colorBtn->setIcon(QIcon(pix));
    }
}
MainWindow::~MainWindow()
{
    delete ui;
}

